package cn.itcast.nems.student.controller.b;

import cn.itcast.ic.common.bean.Page;
import cn.itcast.nems.common.BasePageRequest;
import cn.itcast.nems.oldems.api.StudentApi;
import cn.itcast.nems.oldems.dto.StudentBasicInfoDto;
import cn.itcast.nems.oldems.dto.StudentDataQueryDto;
import cn.itcast.nems.oldems.dto.StudentListDto;
import cn.itcast.nems.oldems.service.StudentService;
import cn.itcast.nems.studentrecord.web.vo.form.StudentRecordMergedCallBack;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/b/student")
@RequiredArgsConstructor
public class StudentController {

    private final StudentApi studentApi;
    private final StudentService studentService;

    @RequestMapping("/page/list")
    public ResponseEntity<Page<StudentListDto>> page(
            @RequestBody BasePageRequest<StudentDataQueryDto> pageRequest
    ) {
        return ResponseEntity.ok(studentApi.page(pageRequest));
    }

    @GetMapping("/basic/info/{studentId}")
    public ResponseEntity<StudentBasicInfoDto> basicInfo(
            @PathVariable("studentId") int studentId
    ) {
        return ResponseEntity.ok(studentApi.studentInfoById(studentId));
    }

    @PutMapping("/basic/info/{studentId}")
    public ResponseEntity<Boolean> basicInfo(@RequestBody StudentBasicInfoDto vo) {
        return ResponseEntity.ok(studentApi.update(vo));
    }

    @PostMapping("/merge")
    public ResponseEntity<Boolean> merge(@RequestBody StudentRecordMergedCallBack query) {
        return ResponseEntity.ok(studentService.merge(query.getFromStudentId(), query.getToStudentId()));
    }

    @GetMapping("/{studentId}/merge_to_list")
    public ResponseEntity<List<StudentListDto>> mergeToList(@PathVariable("studentId") int studentId) {
        return ResponseEntity.ok(studentService.mergeToList(studentId));
    }
}
